<?php

declare(strict_types=1);

namespace App\Service;

use App\Model\SysRole as SysRoleModel;

class SysRole extends BaseService
{
    // 获取角色信息
    public function getInfo($role_id)
    {
        return SysRoleModel::query()->where('role_id', $role_id)->first();
    }


    // 角色列表
    public function roleList($map)
    {
        return SysRoleModel::query()->where($map)->select('role_id', 'role_name', 'rules', 'status', 'created_at', 'updated_at')->orderBy('role_id', 'asc')->get();
    }

    // 添加角色
    public function addSysRole($data)
    {
        $model = new SysRoleModel();
        $model->role_name = $data['role_name'];
        $model->rules = $data['rules'];
        $model->status = $data['status'];
        return $model->save();
    }

    // 编辑角色
    public function editSysRole($role_id, $data)
    {
        $model = (new SysRoleModel())::query()->find($role_id);
        $model->role_name = $data['role_name'];
        $model->rules = $data['rules'];
        $model->status = $data['status'];
        return $model->save();
    }

    // 删除角色
    public function deleteRole($role_id)
    {
        return SysRoleModel::where('role_id', $role_id)->delete();
    }
}
